package system;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet("/auditStudentTest")
public class auditStudentTest extends HttpServlet {
	private static final long serialVersionUID = 1L;
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        int type=Integer.parseInt(req.getParameter("type"));
    	
    	int partNo=Integer.parseInt(req.getParameter("partNo"));
		int questionNo=Integer.parseInt(req.getParameter("questionNo"));
		
		String studentid = req.getParameter("studentid");
		String testid = req.getParameter("testid");
		
		int point=Integer.parseInt(req.getParameter("point"));
		
		String result="";
		
		sqlOperation sql = new sqlOperation();
		
		if(type==1) {
			int update=sql.getUpdate("update student_question_subjective_topic set grade='"+point+"' where test_id='"+testid+"' and student_id='"+studentid+"' and part_no='"+partNo+"' and question_no='"+questionNo+"'");
			update+=sql.getUpdate("update have_subject_topic set isFinished='1'  where test_id='"+testid+"' and student_id='"+studentid+"' and part_no='"+partNo+"' and question_no='"+questionNo+"'");
			update+=sql.getUpdate("update student_test set grade=(select grade from student_question_subjective_topic where student_id='"+studentid+"' and test_id='"+testid+"' and part_no='"+partNo+"' and question_no='"+questionNo+"')+(select grade from student_test where test_id='"+testid+"' and student_id='"+studentid+"') where test_id='"+testid+"' and student_id='"+studentid+"'");
			result = "{\"code\":\""+update+"\"}";
		}else if(type==2) {
			
		}
		
		resp.setContentType("application/json;charset=UTF-8");
		PrintWriter out = resp.getWriter();		
		out.write(result);
		
    }
}
